/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path);
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  return str.trim().length >= 2;
}
export function validMobile(rule, str, callback) {
  if (/^1[3456789]\d{9}$/.test(str)) {
    return callback();
  }
  callback(new Error('请输入正确的手机号'));
}

export const checkIDCard = (rule, card, callback) => {
  const idCardRegexp = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  if (!card || !card.trim()?.length) {
    return callback();
  }
  if (card.length !== 18) {
    return callback(new Error('请输入正确的身份证号'));
  }

  if (!idCardRegexp.test(card)) {
    return callback(new Error('请输入正确的身份证号'));
  }
  return callback();
};
